/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thesis.haipv.qa.comtrust;

import java.util.ArrayList;

/**
 *
 * @author PHANHAI
 */
public class ComTrust {
    
    public static float getExperienceTrust(ArrayList<Transaction> trans) {
        float experienceTrust = 0.0f;
        int n = trans.size();
        for(int i = 1; i <= n; ++i) {
            float x1 = (float)(i-1)/n;
            float x2 = (float) i/n;
            Transaction content = trans.get(i-1);
            content.setWeight(rdm(x1)-rdm(x2));
            experienceTrust += content.getWeight()*content.getTrust();
        }
        return experienceTrust;
    }
    
    public static float getReferienceTrust(ArrayList<Float> expTrust) {
        float referienceTrust = 0.0f;
        float tmp = 0;
        int n = expTrust.size();
        for(float trans : expTrust) {
            tmp += trans;
        }
        referienceTrust = (n == 0)? -1 : tmp/n;
        return referienceTrust;
    }
    
    public static float getComtrust(float e, float we, float r, float wr) {
        return e*we + r*wr;
    }
    
    private static float rdm(float x) {
        return (float) Math.pow(1-x, 4);
    }
    
}
